package Square;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import be.kuleuven.cs.som.annotate.Basic;

import Border.Direction;

public class RegularSquareTeleporter extends RegularSquare implements
		Teleporter {

	/**
	 * 
	 * Creates a new square with a given temperature, humidity percentage and a number of border directions
	 * 
	 * @param 	temperature
	 * 			The temperature the new square will have.
	 * 
	 * @param 	humidity
	 * 			The humidity percentage the new square will have.
	 * 
	 * @param 	directions
	 * 			These are the directions in which a wall has to be added.
	 * 
	 * @effect 	This RegularSquareTeleporter is initialized as a new RegulareSquare with given temperature, humidity and directions
	 * 			| super(temperature, humidity, directions)
	 * 			
	 */
	public RegularSquareTeleporter(double temperature, BigDecimal humidity,Direction... directions) throws IllegalArgumentException {
		super(temperature, humidity, directions);
	}


	/**
	 * ArrayList that contains all the destinations that are 
	 * available for the teleportation
	 */
	private List<DefaultSquare> destinations = new ArrayList<DefaultSquare>();
	

	/**
	 * Adds a destination to the teleporter
	 * @param	square
	 * 			The square to add to this teleporter
	 * @post	The square will be added to this teleporter's destinations
	 * 			| getAllDestinations().contains(square) == true
	 * @note	If the destination is not valid the square won't be added
	 * 			| isValidDestination(square)
	 */
	@Override
	public void addDestination(DefaultSquare square){
		if(isValidDestination(square))
			destinations.add(square);
	}
	
	/**
	 * Checks if the destination is valid or not
	 * @param	square
	 * 			The square to check
	 * @return 	Returns true if and only if the square is effective and the teleporter doesn't contain the square yet
	 * 			| result == ( (square != null) && (!destinations.contains(square)) )
	 */
	@Override
	public boolean isValidDestination(DefaultSquare square) {
		return ( (square != null) && (!destinations.contains(square)) );
	}
	
	/**
	 * Method that returns a list off all the destinations the teleporter can have
	 */
	@Override @Basic
	public List<DefaultSquare> getAllDestinations() {
		return destinations;
	}
	
	/**
	 * Method that removes a certain square from the teleporters' destination
	 * @param	square
	 * 			The destination to remove
	 * @post	The square will be removed from this teleporter's destinations
	 * 			| getAllDestinations().contains(square) == false
	 */
	@Override
	public void removeDestination(DefaultSquare square) {
		destinations.remove(square);		
	}
	
	/**
	 * Method that randomly picks a destination
	 * 
	 * @return	Returns a random destination from this teleporter's destination list
	 * 			| Collections.shuffle(getAllDestinations())
	 *			| result == getAllDestinations().get(0)
	 */
	@Override 
	public DefaultSquare pickTeleportationSquare(){
		Collections.shuffle(getAllDestinations());
		return getAllDestinations().get(0);
	}
	
	/**
	 * Method that is used to obtain the amount of squares the teleporter can teleport to.
	 * 
	 * @return	The amount of destinations the teleporter can teleport to
	 * 			| result == getAllDestinations().size()
	 */
	@Override
	public long getAmountOfDestinations() {
		return getAllDestinations().size();
	}
	
	/**
	 * Method that checks if the square is a validSquare to teleport to.
	 * @param	square
	 * 			The square to teleport to
	 * 
	 * @return	Returns true if an avatar can teleport from this square to the given square
	 * 			| result == (getAllDestinations().contains(square))
	 */
	@Override
	public boolean canTeleportTo(DefaultSquare square) {
		return (getAllDestinations().contains(square));
	}


}
